package com.corner.model.cornerservice.domain;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.annotations.Expose;

public class Info extends BaseBean implements Parcelable {


    public static final String INFO = "Info";
    public static final String BOTTOM_SCALE = "bottomScale";
    public static final String TOP_SCALE = "topScale";
    public static final String RIGHT_SCALE = "rightScale";
    public static final String LEFT_SCALE = "leftScale";
    public static final String SCALE = "scale";
    public static final String USER = "user";
    public static final String GEO_POINT = "geoPoint";
    public static final String IMAGE = "image";
    public static final String AUDIO = "audio";
    public static final String TEXT = "text";
    public static final String TYPE = "type";
    public static final String AREA = "area";
    /******* type *****/
    // 文字
    public static final int T = 1;
    // 图片
    public static final int P = 2;
    // 语音
    public static final int A = 3;
    // 语音表情
    @Deprecated
    public static final int AP = 4;
    // 文字+图片
    public static final int TP = 5;


    @Expose
    private Integer type;
    @Expose
    private CloudFile image;
    @Expose
    private CloudFile audio;
    @Expose
    private String text;
    @Expose
    private Location area;
    @Expose
    private GeoPoint geoPoint;
    @Expose
    private User user;

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Location getArea() {
        return area;
    }

    public void setArea(Location area) {
        this.area = area;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public GeoPoint getGeoPoint() {
        return geoPoint;
    }

    public void setGeoPoint(GeoPoint geoPoint) {
        this.geoPoint = geoPoint;
    }
    public CloudFile getAudio() {
        return audio;
    }

    public void setAudio(CloudFile audio) {
        this.audio = audio;
    }

    public void setImage(CloudFile image) {
        this.image = image;
    }

    public CloudFile getImage() {
        return image;
    }

    /**
     * *******************扩展***************************
     */

    public Boolean isLike;
    public String watchNum;
    public String agreeNum;
    /**
     * 音频是否在播放
     */
    public boolean isPlaying;
    public int marginRight;
    public String id;
    public boolean hasRequestIsLike;
    public boolean hasRequestReadedCount;
    public boolean hasRequestAgreeCount;


    private float[] scale;
    private String imagePath;
    private String audioPath;


    /**
     * 获取图片的显示尺寸
     *
     * @return
     */
    public float[] getScale() {
        if (this.scale == null) {
            if (image!=null&&!TextUtils.isEmpty(image.getMeta())) {
                JSONObject jsonObject = JSONObject.parseObject(image.getMeta());
                scale = new float[4];
                scale[0] = jsonObject.getFloat(LEFT_SCALE);
                scale[1] = jsonObject.getFloat(TOP_SCALE);
                scale[2] = jsonObject.getFloat(RIGHT_SCALE);
                scale[3] = jsonObject.getFloat(BOTTOM_SCALE);
            }
        }
        return this.scale;
    }

    public void setScale(float[] scale) {
        this.scale = scale;
    }

    public String getImagePath() {return imagePath;}

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    public String getAudioPath() {
        return audioPath;
    }

    public void setAudioPath(String audioPath) {
        this.audioPath = audioPath;
    }


    public String getAudioUrl() {
        if (audio!=null){
            return audio.getFileUrl();
        }
        return null;
    }
    public String getImageUrl() {
        if (image!=null){
            return image.getFileUrl();
        }
        return null;
    }

    /**
     * ********************************************************************
     */


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeValue(this.type);
        dest.writeParcelable(this.image, 0);
        dest.writeParcelable(this.audio, 0);
        dest.writeString(this.text);
        dest.writeParcelable(this.area, 0);
        dest.writeParcelable(this.geoPoint, 0);
        dest.writeParcelable(this.user, 0);
        dest.writeValue(this.isLike);
        dest.writeString(this.watchNum);
        dest.writeString(this.agreeNum);
        dest.writeByte(isPlaying ? (byte) 1 : (byte) 0);
        dest.writeInt(this.marginRight);
        dest.writeString(this.id);
        dest.writeByte(hasRequestIsLike ? (byte) 1 : (byte) 0);
        dest.writeFloatArray(this.scale);
        dest.writeString(this.imagePath);
        dest.writeString(this.audioPath);
    }

    public Info() {
    }

    protected Info(Parcel in) {
        super(in);
        this.type = (Integer) in.readValue(Integer.class.getClassLoader());
        this.image = in.readParcelable(CloudFile.class.getClassLoader());
        this.audio = in.readParcelable(CloudFile.class.getClassLoader());
        this.text = in.readString();
        this.area = in.readParcelable(Location.class.getClassLoader());
        this.geoPoint = in.readParcelable(GeoPoint.class.getClassLoader());
        this.user = in.readParcelable(User.class.getClassLoader());
        this.isLike = (Boolean) in.readValue(Boolean.class.getClassLoader());
        this.watchNum = in.readString();
        this.agreeNum = in.readString();
        this.isPlaying = in.readByte() != 0;
        this.marginRight = in.readInt();
        this.id = in.readString();
        this.hasRequestIsLike = in.readByte() != 0;
        this.scale = in.createFloatArray();
        this.imagePath = in.readString();
        this.audioPath = in.readString();
    }

    public static final Creator<Info> CREATOR = new Creator<Info>() {
        public Info createFromParcel(Parcel source) {
            return new Info(source);
        }

        public Info[] newArray(int size) {
            return new Info[size];
        }
    };

}
